package com.example.zhish.explore_demo001;


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.zhish.explore_demo001.R;

import java.util.List;
import java.util.Map;

/**
 * Created by zhish on 2016/4/15.
 */
public class MyAdapter extends BaseAdapter {
    private LayoutInflater mLayoutInflater;
    private List<Explore_item> list;
    private Context context;

    public MyAdapter(List<Explore_item> list, Context context) {
        this.list = list;
        mLayoutInflater = LayoutInflater.from(context);
        this.context = context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = mLayoutInflater.inflate(R.layout.explore_item, null);
            viewHolder.image_icon = (TextView) convertView.findViewById(R.id.image_icon);
            viewHolder.content_file = (TextView) convertView.findViewById(R.id.content_file);
            convertView.setTag(viewHolder);

        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        Explore_item explore_item = list.get(position);
        viewHolder.image_icon.setBackgroundResource(Global.images.get(explore_item.item_extraName));
        viewHolder.content_file.setText(explore_item.getItem_file());

        viewHolder.image_icon.getLayoutParams().height = Global.GLOBAL_HEIGHT / 8;
        viewHolder.image_icon.getLayoutParams().width = Global.GLOBAL_WEIGHT/6;
        //viewHolder.image_icon.getLayoutParams().width = 50;
        //viewHolder.image_icon.getLayoutParams().height = 50;

        return convertView;
    }

    class ViewHolder {
        public TextView image_icon;
        public TextView content_file;
    }
}
